package com.gaoyi.crm.repository;

import com.gaoyi.crm.callback.Callback;
import com.gaoyi.crm.callback.OnResultListener;
import com.gaoyi.crm.util.OKHttpUtil;
import com.gaoyi.crm.util.ThreadManager;
import com.gaoyi.crm.util.Utils;

import java.lang.reflect.Type;

public class ComboRepository {

    public void combo(String typeKey, final OnResultListener onResultListener, Type typeofT) {
        if (Utils.isOnline()) {
            comboOnline(typeKey, onResultListener, typeofT);
        }else {
            combo(typeKey,onResultListener);
        }
    }

    private void combo(String typeKey, OnResultListener onResultListener) {
        if (typeKey.equals("customers")) {
            new CustomerRepository().getShortCustomer(onResultListener);
        }
    }

    public void comboOnline(String typeKey, final OnResultListener onResultListener, Type typeofT) {
        OKHttpUtil.getInstance().getAsync(OKHttpUtil.NET_URL + "/api/utils/combos?typeKey=" + typeKey,
                new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        onResultListener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        onResultListener.onFails(e);
                    }
                }, typeofT);
    }


}
